package com.xufx.thread.liaoxuefeng.thread1_create;

/**
 * Created by xufx on 2021/12/22 12:37
 */
public class CreateNonNullThread {
    public static void main(String[] args) {
        Thread t1 = new MyThread();
        Thread t2 = new Thread(new MyRunnable());
        Thread t3 = new Thread(() -> {
            System.out.println("lambda start new Thread");
        });
        // 设置线程的优先级
        t1.setPriority(1);
        t2.setPriority(2);
        t3.setPriority(3);
        t1.start();
        t2.start();
        t3.start();
    }
}

// 继承Thread类，并覆写run()方法
class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println("thread start new thread");
    }
}

// 创建Thread实例时，传入一个Runnable实例
class MyRunnable implements Runnable{

    @Override
    public void run() {
        System.out.println("runnable start new thread");
    }
}
